import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import moment from 'moment';
import {
	Row, Col, Card, Form, Input, Select, Icon, Button, Dropdown, Menu, InputNumber, DatePicker, Switch, Modal, message, Divider, Upload,
} from 'antd';

import reqwest from 'reqwest';


const FormItem = Form.Item;
const { TextArea } = Input;

@Form.create()
export default class DepartmentModal extends PureComponent {
	constructor(props) {
		super(props);

		console.log('初始化数据', this.props.initValue)

		this.formLayout = {
			labelCol: { span: 7 },
			wrapperCol: { span: 13 },
		};
	}

	okHandle() {
		this.props.form.validateFields((err, fieldsValue) => {
			if (err) return;
			this.props.form.resetFields();
			this.props.addDept(fieldsValue);
		});
	}

	render() {
		const { form } = this.props;
		return (
			<Modal
				width={640}
				bodyStyle={{ padding: '32px 40px 48px' }}
				destroyOnClose
				title="新增部门"
				visible={this.props.visible}
				onOk={() => this.okHandle()}
				onCancel={() => this.props.addModalVisible(false)}
			>
				{(this.props.initValue && this.props.initValue.id != null && this.props.initValue.id != "") ?
					<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="部门编号" style={{ display: 'none' }}>
						{form.getFieldDecorator('id', {
							rules: [{ required: true, message: '请输入部门编号' }],
							initialValue: (this.props.initValue.id != null) ? this.props.initValue.id : "",
						})(<Input placeholder="请输入部门编号" disabled={true} hidden={true} />)}
					</FormItem>
					:
					null
				}
				{(this.props.initValue && this.props.initValue.pid != null && this.props.initValue.pid != "") ?
					<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="上级部门编号" style={{ display: 'none' }}>
						{form.getFieldDecorator('pid', {
							rules: [{ required: true, message: '请输入部门名称' }],
							initialValue: (this.props.initValue.pid != null) ? this.props.initValue.pid : "",
						})(<Input placeholder="请输入部门名称" disabled={true} hidden={true} />)}
					</FormItem>
					:
					null
				}
				{(this.props.initValue && this.props.initValue.pname != null && this.props.initValue.pname != "") ?
					<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="上级部门">
						{form.getFieldDecorator('pname', {
							rules: [{ required: true, message: '请输入上级部门名称' }],
							initialValue: this.props.initValue.pname || null,
						})(<Input placeholder="请输入部门名称" disabled={true} />)}
					</FormItem>
					:
					null
				}
				<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="部门名称">
					{form.getFieldDecorator('name', {
						rules: [{ required: true, message: '请输入部门名称' }],
						initialValue: (this.props.initValue && this.props.initValue.name) || null,
					})(<Input placeholder="请输入部门名称" />)}
				</FormItem>
				<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="部门职能">
					{form.getFieldDecorator('describe', {
						rules: [{ required: true, message: '请输入部门职能' }],
						initialValue: (this.props.initValue && this.props.initValue.describe) || null,
					})(<Input placeholder="请输入部门职能" />)}
				</FormItem>
			</Modal>
		);
	}
}